<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\StockCodes;

class StockCodeController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = "指数代码";

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new StockCodes());

        $grid->column('id', __('Id'));
        $grid->column('code', __('股票代码'));
        $grid->column('title', __('股票名称'));
        $grid->column('index_temperture', __('长投温度'));
        $grid->column('computed_at', __('计算事件'));
        $grid->column('api', __('Api'));
        $grid->column('type', __('指数类型'));
        $grid->column('pb_temp', __('PB温度'));
        $grid->column('pe_temp', __('PE温度'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(StockCodes::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('code', __('Code'));
        $show->field('title', __('Title'));
        $show->field('index_temperture', __('Index temperture'));
        $show->field('computed_at', __('Computed at'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));
        $show->field('api', __('Api'));
        $show->field('type', __('Type'));
        $show->field('pb_temp', __('Pb temp'));
        $show->field('pe_temp', __('Pe temp'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new StockCodes());

        $form->text('code', __('Code'));
        $form->textarea('title', __('Title'));
        $form->decimal('index_temperture', __('Index temperture'));
        $form->datetime('computed_at', __('Computed at'))->default(date('Y-m-d H:i:s'));
        $form->text('api', __('Api'));
        $form->text('type', __('Type'));
        $form->decimal('pb_temp', __('Pb temp'));
        $form->decimal('pe_temp', __('Pe temp'));

        return $form;
    }
}
